package utils

import (
	"fmt"
	"os"
	"path"
	"path/filepath"
)

func FileExists(filename string) (bool, error) {
	fileInfo, err := os.Stat(filename)

	return nil == err && !fileInfo.IsDir(), err
}

func DirExists(pathname string) (bool, error) {
	fileInfo, err := os.Stat(pathname)
	return err == nil && fileInfo.IsDir(), err
}

func MkDirs(dirName string) error {
	return os.MkdirAll(dirName, os.FileMode(0666))
}

// FilePathJoin 跨平台的 用作目录的join
func FilePathJoin(pathname ...string) string {
	return filepath.Join(pathname...)
}

//  PathJoin 用作url的join
func PathJoin(pathname ...string) string {
	return path.Join(pathname...)
}

// 获取上传路径深度
func GetUploadPathDeep(defaultPath string, deep int) string {
	for i := 0; i < deep; i++ {
		defaultPath = FilePathJoin(defaultPath, fmt.Sprintf("%d", GetIntnRand(65535)))
	}
	return defaultPath
}

